//
//  OosactivityDao.m
//  Oos4ios
//
//  Created by Pablo Gonzalez on 3/21/11.
//  Copyright 2011 11870.com. All rights reserved.
//

#import <oos4ios/DAOs/OosActivityDao.h>
#import "../../Atom/Services/OosAtomService.h"
#import "../../Atom/Queries/OosActivityQuery.h"
#import "../../Atom/Feeds/OosActivityFeed.h"
#import "../../Parsers/OosActivityFeedParser.h"


@implementation OosActivityDao

+ (OosActivityDao *) daoFromUser:(OosUser *)user
{
	return [[[OosActivityDao alloc] initFromUser: user] autorelease];
}

+ (OosActivityDao *) daoFromUserSlug:(NSString *)userSlug
{
	return [[[OosActivityDao alloc] initFromUserSlug: userSlug] autorelease];
}

- (OosActivityDao *) initFromUser:(OosUser *)user
{
	self = [self initFromUserSlug: [user slug]];
	if (self) {
		self->mUser = [user retain];
	}
	return self;
}

- (OosActivityDao *) initFromUserSlug:(NSString *)userSlug
{
	self = [self init];
	if (self) {
		self->mUserSlug = [userSlug retain];
	}
	return self;
}

@synthesize social;

- (OosQuery *) query
{
	OosQuery *query = nil;
	if (social) {
		query = [OosActivityQuery queryForSocialUserSlug: mUserSlug];
	} else {
		query = [OosActivityQuery queryForUserSlug: mUserSlug];
	}
	[query packStore: self.options];
	return query;
}

- (void)initAtomService:(OosAtomService *)service
{
    service.feedClass = [OosActivityFeed class];
}

- (id <IOosFeedParser>) feedParser
{
	return [OosActivityFeedParser instance];
}

- (void)dealloc
{
    [mUser release];
    [mUserSlug release];
    [super dealloc];
}

@end
